﻿package mortal.game.resource.info
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;

    public class TalkInfo extends TTalk
    {
        private var _isInitTalks:Boolean = false;
        private var talkArray:Vector.<TalkProb>;
        public var talkStr:String;
        public var talkNextTime:int;

        public function TalkInfo()
        {
            this.talkArray = new Vector.<TalkProb>;
            return;
        }// end function

        public function randomTalk() : String
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (!this._isInitTalks)
            {
                this.initTalk();
            }
            this.talkStr = "";
            var _loc_1:* = Math.random() * 100;
            if (_loc_1 > this.totalProb)
            {
                this.talkStr = "";
            }
            else
            {
                _loc_2 = Math.random() * 100;
                _loc_3 = 0;
                while (_loc_3 < this.talkArray.length)
                {
                    
                    if (_loc_2 <= this.talkArray[_loc_3].prob)
                    {
                        this.talkStr = this.talkArray[_loc_3].content;
                        this.talkNextTime = this.talkArray[_loc_3].talkNextTime;
                        break;
                    }
                    _loc_3++;
                }
            }
            return this.talkStr;
        }// end function

        private function initTalk() : void
        {
            var _loc_4:Array = null;
            var _loc_5:int = 0;
            var _loc_6:TalkProb = null;
            var _loc_1:* = this.content.split("&");
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_4 = String(_loc_1[_loc_3]).split("#");
                _loc_5 = int(_loc_4[0]);
                _loc_2 = _loc_2 + _loc_5;
                _loc_6 = new TalkProb(_loc_2, String(_loc_4[1]), int(_loc_4[2]));
                this.talkArray.push(_loc_6);
                _loc_3++;
            }
            this._isInitTalks = true;
            return;
        }// end function

    }
}

class TalkProb extends Object
{
    public var prob:int;
    public var content:String;
    public var talkNextTime:int;

    function TalkProb(param1:int, param2:String, param3:int)
    {
        this.prob = param1;
        this.content = param2;
        this.talkNextTime = param3;
        return;
    }// end function

}

